<?php
require_once $ubi['SERVER']['SERVER_ROOT'] . '/controller/ctlAbstract.php';

require_once $ubi['SERVER']['SERVER_ROOT'] . '/business/busQuick_Message.php';
require_once $ubi['SERVER']['SERVER_ROOT'] . '/business/busAvatar.php';

class QuickMessageController extends AbstractController {
	private $_quickMessageBus;
	private $_avatarBus;
	
	public function main(array $getVars) {
		global $ubi;
		
		$this->_quickMessageBus = new Quick_MessageBus();
		$this->_avatarBus = new AvatarBus();	
		
		if ($getVars['type'] == 'loadAll') {
			if (isset($getVars['userid'])) {
				if (!isset($getVars['page'])) {
					$getVars['page'] = 1;
				}		
								
				$quickMessages = $this->_quickMessageBus->getQuickMessagesOfPage($getVars['userid'], $getVars['page']);
				
				$users = $this->_quickMessageBus->getSendersFromQuickMessage($quickMessages);
				$imgs = $this->_avatarBus->getAvatarPathOfUsers($users);
				
				require_once $ubi['SERVER']['SERVER_ROOT'] . '/view/viewQM.php';
			}
		} else if ($getVars['type'] == 'load') {
			if (isset($getVars['userid'])) {
				$nQuickMessage = $this->_quickMessageBus->countQuickMessage($getVars['userid']);
				
				$numberOfPages = (int)($nQuickMessage
									/ $ubi['QUICK_MESSAGE']['MESSAGE_PER_PAGE'] + 1);

				require_once $ubi['SERVER']['SERVER_ROOT'] . '/view/viewAllQuickMessages.php';
			}
		} 
	}
} 
?>